@extends('wechat.layouts.base')
@section("js_files")
    <script src="{{asset('dist/wechat/js/share_file.js')}}"></script>
@endsection
@section('content')
		<div class="weui_dialog_alert" style="display: none;">
			<div class="weui-mask" style="width:640px;height:1010px;"></div>
			<div class="weui-dialog" style="top:51%;">
				<div class="weui-dialog__hd"><strong class="weui-dialog__title">弹窗标题</strong></div>
				<div class="weui-dialog__bd" style="max-height:200px;overflow:scroll;">弹窗内容，告知当前页面信息等</div>
				<div class="weui-dialog__ft">
					<a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary">确定</a>
				</div>
			</div>
		</div>
		<div class="fill">
            <div class="formmsg"><h4>请输入真实信息以便领取奖品</h4></div>
            <div class="weui-cells weui-cells_form">
                <div class="weui-cell">
                    <div class="weui-cell__hd"><label class="weui-label">姓名</label></div>
                    <div class="weui-cell__bd">
                        <input id ="username" name="username" class="weui-input" type="text" placeholder="请输入姓名"/>
                    </div>
                </div>
                <div class="weui-cell weui-cell_vcode">
                    <div class="weui-cell__hd">
                        <label class="weui-label">手机号</label>
                    </div>
                    <div class="weui-cell__bd">
                        <input id ="phone" name="phone" class="weui-input" type="tel" placeholder="请输入手机号">
                    </div>
					<div class="weui-cell__ft">
						<input style="width:100%; font-size:12px;" type="button" id="getCode" class="weui-vcode-btn" value="获取验证码"/>
					</div>
                </div>
				<div class="weui-cell">
                    <div class="weui-cell__hd"><label class="weui-label">验证码</label></div>
                    <div class="weui-cell__bd">
                        <input class="weui-input" type="number"  id="code" placeholder="请输入验证码"/>
                    </div>
                </div>
            </div>
			<label for="weuiAgree" class="weui-agree">
                <input id="weuiAgree" type="checkbox" class="weui-agree__checkbox" checked>
                <span class="weui-agree__text">
                    阅读并同意<a id="term" href="javascript:void(0);">《用户使用协议》</a>
                </span>
            </label>
            <div class="sure"><a id="submit" href="javascript:;">确定</a></div>
			<!--
			<input name="username" id ="username"type="text" placeholder="输入姓名">
			<input name="phone"  id ="phone" type="text" placeholder="输入手机号码">
			<button id="submit">提交</button>
			-->
		</div>
@endsection

@section('js')
    <script type="application/javascript">
		$.weui = {};
			$.weui.alert = function(options){
				options = $.extend({title: '提示', text: '警告内容'}, options);
				var $alert = $('.weui_dialog_alert');
				$alert.find('.weui-dialog__title').text(options.title);
				$alert.find('.weui-dialog__bd').html(options.text);
				$alert.on('touchend click', '.weui-dialog__btn', function(){
					$alert.hide();
				});
				$alert.show();
			};
        $(function () {
            var token = "{{ csrf_token() }}";
            var p_log_id  = "{{$id}}";

            $('#submit').on('click',function () {
                var username = $('#username').val();
                var phone  = $('#phone').val();
                var code = $("#code").val();
				var radio = $("#weuiAgree").attr("checked");
                if(code) {
                    if (username && phone && radio) {
                        $.ajax({
                            url: "{{url('wechat/mine/submit')}}",
                            type: "Post",
                            typdData: "json",
                            async: false,
                            data: {
                                username: username, phone: phone, _token: token,code:code
                            },
                            success: function (data) {
                                if (data.success == true) {
                                    //alert(data.msg);
									$.weui.alert({text: data.msg});
                                    if (p_log_id) {
                                        window.location.href = "{{url('wechat')}}/" + p_log_id + "/upload";
                                    } else {
                                        window.history.back(-1);
                                    }
                                } else {
                                    //alert(data.msg);
									$.weui.alert({text: data.msg});
								}
                            }
                        });
                    } else {
						$.weui.alert({text: "姓名与手机号码不能为空!"});
                        //alert("姓名与手机号码不能为空!");
                    }
                }else{
					$.weui.alert({text: "验证码不能空!"});
                    //alert("验证码不能空!");
                }
            });

            //发送短信
            var InterValObj; //timer变量，控制时间
            var count = 60; //间隔函数，1秒执行
            var curCount=0;//当前剩余秒数

            $("#getCode").on("click",function () {
                var phone  = $('#phone').val();
                curCount = count;
                if(phone){
                    $.ajax({
                        url: "{{url('wechat/mine/send/sms')}}",
                        type: "Post",
                        typdData: "json",
                        async: false,
                        data:{
                            phone:phone,_token: token
                        },
                        success:function (data) {
                              if(data.success == true){
                                  $("#getCode").attr("disabled", "true");
                                  $("#getCode").val("请在" + curCount + "秒内输入验证码");
                                  InterValObj = window.setInterval(SetRemainTime,1000); //
                              }else{
								  $.weui.alert({text: data.msg});
                                    //alert(data.msg);
                              }
                        }
                    });
                }else{
					$.weui.alert({text: "手机号码不能为空"});
                    //alert("手机号码不能为空");
                }
            });

            //timer处理函数
            function SetRemainTime() {
                if (curCount == 0) {
                    window.clearInterval(InterValObj);//停止计时器
                    $("#getCode").removeAttr("disabled");//启用按钮
                    $("#getCode").val("重新获取验证码").removeAttr("disabled");
                    clearInterval(InterValObj);
                }
                else {
                    curCount--;
                    $("#getCode").val("请在" + curCount + "秒内输入验证码");
                }
            }
            function stopTime(){
                curCount=0;
                InterValObj = window.setInterval(SetRemainTime,1000); //启动计时器，1秒执行一次
            }
			
			$("#term").on('click',function(){
				var p = '<p>1、用户在注册账号或使用本系统的过程中，可能需要填写或提交一些必要的信息，如法律法规、规章规范性文件（以下称“法律法规”）规定的需要填写的身份信息。如用户提交的信息不完整或不符合法律法规的规定，则用户可能无法使用本系统或在使用本系统的过程中受到限制。</p><p>2、个人隐私信息是指涉及用户个人身份或个人隐私的信息，比如，用户真实姓名、手机号码、手机设备识别码；</p><p>百万民选系统尊重用户个人隐私信息的私有性，百万民选将采取技术措施和其他必要措施，确保用户个人隐私信息安全，防止在本系统中收集的用户个人隐私信息泄露、毁损或丢失。在发生前述情形或者百万民选系统发现存在发生前述情形的可能时，将及时采取补救措施。</p><p>您在百万民选系统中提供的个人信息包括照片微信昵称，百万民选系统拥有默认授权使用的权力，可将您上传的照片及微信昵称用于非商业性质的传播。</p>';
				$.weui.alert({text: p});
			});
        });
    </script>
@endsection